home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_2.arc / TASK.HXX < prev    next >
Text File  |  1988-12-21  |  1KB  |  60 lines

  1. // task.hxx
  2. //
  3. // implements the Task class.  this manages the spawning of an OS/2 thread.
  4. //
  5. // author: vaughn vernon
  6. // (c) Copyright 1988 Aspen Scientific
  7. // All Rights Reserved.
  8.  
  9. #ifndef __TASKCLASS__
  10. # define __TASKCLASS__
  11. # ifndef APIENTRY
  12. #    include <os2def.h>
  13. # endif
  14. # ifndef INCL_DOS
  15. #    define INCL_DOS
  16. #    include <bsedos.h>
  17. # endif
  18.  
  19. // the Task class
  20.  
  21. class Task {
  22.  
  23.     USHORT    returnCode;
  24.  
  25. public:
  26.  
  27.     // constructor, it spawns the thread
  28.     Task( VOID auto (FAR * routine)(), USHORT stackSize ) {
  29.  
  30.         PBYTE stack;    // the stack pointer
  31.         TID taskID;    // the thread/task ID
  32.  
  33.         stack = (PBYTE) new BYTE[ stackSize ];
  34.  
  35.         if ( stack != PBYTE(0) ) {
  36.  
  37.             // the stack grows down
  38.             stack += stackSize;
  39.  
  40.             // spawn thread
  41.             returnCode = DosCreateThread( routine,
  42.                     (PTID) &taskID, (PBYTE) stack );
  43.         }
  44.         else
  45.             returnCode = TRUE;    // in this case bad
  46.     }
  47.  
  48.     // the destructor does nothing
  49.     // the stack is freed by OS/2 when the Task completes.
  50.     ~Task()        { ; }
  51.  
  52.     // methods
  53.  
  54.     // was the thread executed?
  55.     BOOL    GetStatus()    {
  56.         return returnCode ? FALSE:TRUE;
  57.     }
  58. };
  59. #endif
  60.